package com.jwdf.uda.view.imagegetter;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.Display;

import com.jwdf.uda.R;

/**
 * Created by Administrator on 2016/9/14.
 */
public class URLDrawable extends BitmapDrawable {
    protected Drawable drawable;

    @SuppressWarnings("deprecation")
    public URLDrawable(Context context)
    {
        this.setBounds(getDefaultImageBounds(context));

        drawable = context.getResources().getDrawable(R.mipmap.image_loading_in_text_24);
        drawable.setBounds(0,0,drawable.getIntrinsicWidth(),drawable.getIntrinsicHeight());
    }
    @SuppressWarnings("deprecation")
    public Rect getDefaultImageBounds(Context context) {
        Display display = ((Activity)context).getWindowManager().getDefaultDisplay();
        int width = display.getWidth();
        int height = width * 3 / 4;

        Rect bounds = new Rect(0, 0, width, height);
        return bounds;
    }
    @Override
    public void draw(Canvas canvas) {
        if(drawable != null) {
            drawable.draw(canvas);
        }
    }
}

